<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class HhmGoodsCategory extends Model
{
    use SoftDeletes;

    protected $table = 'ims_hhm_goods_category';
    
    protected $fillable = [
        'goods_id', 'category_id', 'category_ids', 'goods_option_id'
    ];

    protected $casts = [
        'category_ids' => 'json',
    ];

    const CREATED_AT = 'created_at';
    const UPDATED_AT = 'updated_at';
    const DELETED_AT = 'deleted_at';

    // 禁用时间戳自动转换为Carbon对象，因为表中使用整型存储
    public $timestamps = true;
    protected $dateFormat = 'U'; // 使用Unix时间戳

    /**
     * 关联商品
     */
    public function goods()
    {
        return $this->belongsTo(HhmGoods::class, 'goods_id', 'id');
    }

    /**
     * 关联分类
     */
    public function category()
    {
        return $this->belongsTo(HhmCategory::class, 'category_id', 'id');
    }

    /**
     * 关联商品SKU选项
     */
    public function goodsOption()
    {
        return $this->belongsTo(HhmGoodsOption::class, 'goods_option_id', 'id');
    }
}

